//go:build windows

package osx

import (
	"os"
	"syscall"
)

const (
	kernel32dll = "kernel32.dll"
)

func RedirectStdoutStdErr(filename string) {
	redirectFile, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
	if err != nil {
		panic(err)
	}
	kernel32 := syscall.NewLazyDLL(kernel32dll)
	setStdHandle := kernel32.NewProc("SetStdHandle")
	sh := syscall.STD_ERROR_HANDLE
	v, _, err := setStdHandle.Call(uintptr(sh), redirectFile.Fd())
	if v == 0 {
		panic(err)
	}
}
